<script setup>
import {Plus} from "@element-plus/icons-vue";
import {httpUpload} from "@/api";

const props = defineProps({
  image: {
    type: String,
    default: ''
  },
  imageUrl: {
    type: String,
    default: ''
  }
})
const emits = defineEmits(['update:image', 'update:imageUrl'])

const uploadAvatar = (file) => {
  // 上传头像
  httpUpload(file.file).then(res => {
    emits('update:image', res.data.id)
    emits('update:imageUrl', res.data.fullFileUrl)
  })
}
</script>

<template>
  <el-upload
      class="avatar-uploader"
      action="#"
      :http-request="uploadAvatar"
      :show-file-list="false"
      accept="image/*"
  >
    <el-image v-if="imageUrl" :src="imageUrl" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  </el-upload>
</template>

<style scoped lang="scss">

</style>